[IA64] protect ridblock_owner.
authorIsaku Yamahata <yamahata@valinux.co.jp>
Tue, 28 Oct 2008 05:31:58 +0000 (14:31 +0900)
committerIsaku Yamahata <yamahata@valinux.co.jp>
Tue, 28 Oct 2008 05:31:58 +0000 (14:31 +0900)
protect ridblock_owner by spin lock.
deallocate_rid() is called by arch_domain_destroy() which
is called as rcu callback.
On the other hand allocate_rid() is called from domctl hypercall.
So the access to ridblock_owner is racy.
Protect it by spin lock.
So far probably xend serializes creating domains, so it hasn't
been caused issues.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
xen/arch/ia64/xen/regionreg.c

index f2ef96c06060f8c73d7c25efec8d7fe653ec8daf..c23cb903e8dac95e8c99282df4fcf6d5eb8a4a1f 100644 (file)
@@ -100,6 +100,7 @@ static unsigned long allocate_metaphysical_rr(struct domain *d, int n)
 
 static int implemented_rid_bits = 0;
 static int mp_rid_shift;
+static DEFINE_SPINLOCK(ridblock_lock);
 static struct domain *ridblock_owner[MAX_RID_BLOCKS] = { 0 };
 
 void __init init_rid_allocator (void)
@@ -169,6 +170,7 @@ int allocate_rid_range(struct domain *d, unsigned long ridbits)
        n_rid_blocks = 1UL << (ridbits - IA64_MIN_IMPL_RID_BITS);
        
        // skip over block 0, reserved for "meta-physical mappings (and Xen)"
+       spin_lock(&ridblock_lock);
        for (i = n_rid_blocks; i < MAX_RID_BLOCKS; i += n_rid_blocks) {
                if (ridblock_owner[i] == NULL) {
                        for (j = i; j < i + n_rid_blocks; ++j) {
@@ -182,16 +184,19 @@ int allocate_rid_range(struct domain *d, unsigned long ridbits)
                                break;
                }
        }
-       
-       if (i >= MAX_RID_BLOCKS)
+
+       if (i >= MAX_RID_BLOCKS) {
+               spin_unlock(&ridblock_lock);
                return 0;
-       
+       }
+
        // found an unused block:
        //   (i << min_rid_bits) <= rid < ((i + n) << min_rid_bits)
        // mark this block as owned
        for (j = i; j < i + n_rid_blocks; ++j)
                ridblock_owner[j] = d;
-       
+       spin_unlock(&ridblock_lock);
+
        // setup domain struct
        d->arch.rid_bits = ridbits;
        d->arch.starting_rid = i << IA64_MIN_IMPL_RID_BITS;
@@ -221,11 +226,12 @@ int deallocate_rid_range(struct domain *d)
        if (d->arch.rid_bits == 0)
                return 1;
 
-       
+       spin_lock(&ridblock_lock);
        for (i = rid_block_start; i < rid_block_end; ++i) {
                ASSERT(ridblock_owner[i] == d);
                ridblock_owner[i] = NULL;
        }
+       spin_unlock(&ridblock_lock);
 
        d->arch.rid_bits = 0;
        d->arch.starting_rid = 0;